<template>
  <node 
    :title="config.name" 
    :show-error="showError" 
    :content="content" 
    :error-info="errorInfo"
    @selected="$emit('selected')" 
    @delNode="$emit('delNode')" 
    @insertNode="type => $emit('insertNode', type)"
    placeholder="请设置延时" 
    header-bgc="#f56c6c" 
    header-icon="el-icon-time"/>
</template>

<script>
import Node from './Node'

export default {
  name: "DelayNode",
  props: {
    config: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  components: { Node },
  data() {
    return {
      showError: false,
      errorInfo: '',
    }
  },
  computed: {
    content() {
      const config = this.config.props
      if (config.time && config.time > 0) {
        const unitMap = {
          'M': '分钟',
          'H': '小时',
          'D': '天'
        }
        return `延时${config.time}${unitMap[config.unit] || '分钟'}`
      } else {
        return '请设置延时时间'
      }
    }
  },
  methods: {
    validate() {
      if (this.config.props?.time && this.config.props.time > 0) {
        this.showError = false
        return true
      } else {
        this.showError = true
        this.errorInfo = "请设置延时时间"
        return false
      }
    }
  }
}
</script>

<style lang="less" scoped>

</style>
